/**
 * 
 */
package com.exe.project.data;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

import com.exe.project.entities.User;
import com.exe.project.interfaces.IReadDataUser;

/**
 * @author Executor
 *
 */
public class ReadDataUser implements IReadDataUser {
	private User user=null;
	private BufferedReader brRead=null;
	private String line="";
	private String path ="";
	private StringTokenizer st=null;
	public void setPath(String path){
		this.path = path;
	}
	public ReadDataUser(String name, String pasword){
		user = new User(name, pasword);
	}
	
	public boolean validateUser(){
		try {
			brRead = new BufferedReader(new FileReader(path));
			while((line = brRead.readLine()) != null){
				st = new StringTokenizer(line,",");
				if(st.nextElement().toString().compareToIgnoreCase(user.getUser()) == 0 ){
					if(st.nextElement().toString().compareToIgnoreCase(user.getPasword()) == 0 ){
						return true;
					}
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return false;
	}
}